package com.bjpowernode.style;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程创建方式四：基于线程池的方式实现
 *
 */
public class Test04 implements Runnable {

    @Override
    public void run() {
        System.out.println("线程执行......");
    }

    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(5);

        for (int i = 0; i < 10; i++) {
            Test04 thread = new Test04();
            executorService.execute(thread);
        }

        //关闭线程池
        executorService.shutdown();

        //main线程执行
        System.out.println("main方法执行");
    }
}